<?php
class ControllerWxpayPayorder extends Controller {

    public function index()
    {
        if (!$this->actionCheck(true,false)) {
            return;
        }

        if(!isset($this->session->data['wx_openid']))
        {
            $this->response->setDataResult(0,"缺少用户opeon_id",null);
            return;
        }


        $this->load->model('checkout/order');
        $productnames = '';
        $total_fee = 0;

        if(isset($this->request->get['order_id']))
        {
            $order_id = $this->request->get['order_id'];

            $order_info = $this->model_checkout_order->getOrder($order_id);

            $products = $this->model_checkout_order->getOrderProducts($order_id)->rows;

            if($products)
            {
                foreach ($products as $product)
                {
                    $productnames = $productnames . ($productnames!=''?'， ':'') . $product['name'];
                }
            }


            $total = $order_info['total'];

            $payhelper = new WeixinpayHelper();

            $wxparameters = $payhelper->createPayParameter($this->session->data['wx_openid'], $order_id, $productnames, $total);


            $this->response->setDataResult(1,"",$wxparameters);

            return;
        }
        else
        {
            $this->response->setDataResult(0,"缺少订单Id",null);
        }
    }

}